package com.video.controller;

import com.video.dto.AddCommentDTO;
import com.video.dto.CommentDTO;
import com.video.entity.Comments;
import com.video.result.ResultVO;
import com.video.service.CommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author baoshuai
 * @date 2022/12/15
 */
@CrossOrigin
@Api(tags = "评论接口模块")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentsService commentsService;

    @ApiOperation("查询短视频评论")
    @GetMapping("/{vlogId}")
    public ResultVO getCommentsByVlogId(@PathVariable Long vlogId) {
        List<Comments> comments = commentsService.getCommentsByVlogId(vlogId);
        Long totalComments = commentsService.countVlogComments(vlogId);

        Map<String, Object> map = new HashMap<>(2);
        map.put("comments", comments);
        map.put("totalComments", totalComments);
        return ResultVO.success(map);
    }

    @ApiOperation("删除评论")
    @DeleteMapping
    public ResultVO deleteComment(@RequestBody CommentDTO commentDTO) {
        return commentsService.deleteComment(commentDTO);
    }

    @ApiOperation("添加评论")
    @PostMapping("/addComment")
    public ResultVO addComment(@RequestBody AddCommentDTO addCommentDTO) {
        return commentsService.addComment(addCommentDTO.getUserId(), addCommentDTO.getVlogId(), addCommentDTO.getContent());
    }

    @ApiOperation("点赞/取消 评论")
    @PostMapping("/like/{userId}/{commentId}")
    public ResultVO likeComment(@PathVariable Long userId,
                                @PathVariable Long commentId) {
        return commentsService.likeComment(userId, commentId);
    }


}
